//Lab #5  Yet another Temperature example
//Lots motre comments are need here!!!!

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;		

public class TempApplet extends Applet implements ActionListener 
{
	Panel		panF, panC;
	Label		labF, labC;
	TextField	textF, textC;
	Button		convButton;
	
	public void init() 
	{
		setLayout(new BorderLayout());
		
		panF = new Panel();
		panC = new Panel();
		
		labF = new Label("Fahr:");
		panF.add(labF);		//add to panel F
		textF = new TextField(15);
		panF.add(textF);
		add("North", panF);
		
		labC = new Label("Cent:");
		panC.add(labC);		//add to panel C
		textC = new TextField(15);
		panC.add(textC);
		add("Center", panC);
		
		convButton = new Button("Convert");
		add("South",convButton);
		
		// Register Component Listeners
		textF.addActionListener(this);
		textC.addActionListener(this);
		convButton.addActionListener(this);	
	}
	
	public void actionPerformed (ActionEvent e) 
	{
		DecimalFormat twoDigits = new DecimalFormat("0.00");
		if ((e.getSource() == textF)||(e.getSource() == convButton))
		{
			Double temp = new Double(textF.getText());
			double d = temp.doubleValue();
			d = 5*(d-32.0)/9;	//d = (d - 32.0)/1.8
			textC.setText(String.valueOf(twoDigits.format(d)));
		}
		else
		{
			Double temp = new Double(textC.getText());
			double d = temp.doubleValue();
			d = (9.0/5.0)*d +32.0;	
			textF.setText(String.valueOf(twoDigits.format(d)));
		}
	}
}